<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首字母大写</title>
</head>

<body>
    <script>
        var str = prompt("请输入想要想要首字母大写的英文");
        var UpStr = "";
        for (var i = 0; i <= str.length; i++) {
            if (i == 0) {
                UpStr = str.substring(0, 1).toUpperCase();
            } else {
                UpStr += str.substring(i, i + 1);
            }
        }
        alert(UpStr);
    </script>
</body>

</html>